<!--工艺分组选择框-->
<template>
  <div>
    <BasicModal v-bind="$attrs" @register="register" :title="modalTitle" width="800px" @ok="handleOk" destroyOnClose @visible-change="visibleChange">
      <BasicTable
        :columns="columns"
        v-bind="config"
        :useSearchForm="true"
        :formConfig="formConfig"
        :api="getProcessGroupList"
        :searchInfo="searchInfo"
        :rowSelection="rowSelection"
        :indexColumnProps="indexColumnProps"
      ></BasicTable>
    </BasicModal>
  </div>
</template>
<script lang="ts">
  import { defineComponent, ref, unref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import {getProcessGroupList} from './base.api';
  import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
  import { useSelectBiz } from '/@/components/Form/src/jeecg/hooks/useSelectBiz';
  import { selectProps } from '/@/components/Form/src/jeecg/props/props';
  import { useAttrs } from '/@/hooks/core/useAttrs';

  export default defineComponent({
    name: 'CalculateSelectModal',
    components: {
      //此处需要异步加载BasicTable
      BasicModal,
      BasicTable: createAsyncComponent(() => import('/@/components/Table/src/BasicTable.vue'), {
        loading: true,
      }),
    },
    props: {
      ...selectProps,
      //选择框标题
      modalTitle: {
        type: String,
        default: '工艺分组选择',
      },
    },
    
    emits: ['register', 'getSelectResult'],
    setup(props, { emit}) {
      //注册弹框
      const [register, { closeModal }] = useModalInner(async (data)=>{});
      const attrs = useAttrs();
      //表格配置
      const config = {
        canResize: false,
        bordered: true,
        size: 'small',
        rowKey: unref(props).rowKey,
        labelKey:'name',
        isRadioSelection:true,
      };
      const getBindValue = Object.assign({}, unref(props), unref(attrs), config);
      const [{ rowSelection, indexColumnProps, visibleChange, getSelectResult }] = useSelectBiz(getProcessGroupList, getBindValue);
      rowSelection.columnWidth = 50;
      indexColumnProps.width = 50;
      const searchInfo = ref(props.params);
      //查询form
      const formConfig = {
        labelWidth: 100,
        baseColProps: {
          xs: 8,
          sm: 8,
          md: 8,
          lg: 8,
        },
        schemas: [{
            label:"分组编号",
            field: 'code',
            component: 'JInput',
            colProps: { span: 8 },
          },
          {
            label: '分组名称',
            field: 'name',
            component: 'JInput',
            colProps: { span: 8 },
          },
        ],
      };
    //   useModal((data: any) => {
    //     console.log(data);
    //   });
      //定义表格列
      const columns = [
        {
          title: '分组编号',
          dataIndex: 'code',
          align: 'left',
        },
        {
          title: '分组名称',
          dataIndex: 'name',
        },
        {
          title: '是否启用',
          dataIndex: 'enabledStatus',
          customRender: ({ text }) => {
            return text==1?'是':'否'
          },
        },
        {
          title: '备注',
          dataIndex: 'remark ',
        },
      ];

      /**
       * 确定选择
       */
      function handleOk() {
        getSelectResult((options, values) => {
          //回传选项和已选择的值
          emit('getSelectResult', options, values);
          //关闭弹窗
          closeModal();
        });
      }

      return {
        config,
        handleOk,
        searchInfo,
        register,
        indexColumnProps,
        visibleChange,
        getProcessGroupList,
        formConfig,
        getBindValue,
        columns,
        rowSelection,
      };
    },
  });
</script>
